<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="plugins/jQuery/jQuery-2.2.0.min.js"></script>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=2Kdu1GZSiRWUQZLqPrD4hycyNaoLsVrO 	"></script>

<style type="text/css">
	#map label{max-width:none;}
</style>

<title>线路管理</title>

<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
<!-- Bootstrap 3.3.6 -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet"
	href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- Ionicons -->
<link rel="stylesheet"
	href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
<!-- Theme style -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/dist/css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/dist/css/skins/_all-skins.min.css">
<!-- iCheck -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/iCheck/flat/blue.css">
<!-- Morris chart -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/morris/morris.css">
<!-- jvectormap -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
<!-- Date Picker -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/datepicker/datepicker3.css">
<!-- Daterange picker -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker-bs3.css">
<!-- bootstrap wysihtml5 - text editor -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/dist/css/theme.css"
	media="all">

</head>

<body class="hold-transition skin-blue sidebar-mini"
	style="font-family:Microsoft YaHei;" >
	<div class="wrapper">
		
		<header class="main-header">
			<!-- Logo -->
			<div class="logo" style="background-color:#ec7500;">
				<!-- logo for regular state and mobile devices -->
				<span class="logo-lg"><b
					style="font-size:18px;margin-left:-40px ">厂车管理系统</b> </span>
			</div>
			<!-- Header Navbar: style can be found in header.less -->
			<nav class="navbar navbar-static-top"
				style="background-color:#ec7500;">
				<!-- Sidebar toggle button-->
				<a href="#" class="sidebar-toggle" data-toggle="offcanvas"
					role="button"> <span class="sr-only">Toggle navigation</span> </a>

				<div class="navbar-custom-menu">
					<ul class="nav navbar-nav">
						<!-- User Account:-->
						<li class="dropdown user user-menu"><span class="hidden-xs"></span>
						</li>
						<li style="color:#ffffff; background:#959595;padding:15px">${sessionScope.CurrentUser.username}</li>
						<li><a><i class="fa fa-sign-out"></i> </a>
						</li>
					</ul>
				</div>
			</nav>
		</header>
		<!-- Left side column. contains the logo and sidebar -->
		<aside class="main-sidebar">
			<!-- sidebar: style can be found in sidebar.less -->
			<section class="sidebar">
				<!-- sidebar menu: : style can be found in sidebar.less -->
				<ul class="sidebar-menu">
		<c:forEach var = "UserRoleActionsId"  items = "${sessionScope.CurrentUserActionsId}">
		  <c:choose>
		    <c:when test ="${UserRoleActionsId == 4 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/showEmps.do"> <i
					class="fa fa-user"></i><span>员工管理</span>
					 </a></li>
					 </c:when>
					 <c:when test ="${UserRoleActionsId == 8 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/showBuses.do"> <i class="fa fa-bus"></i>
					<span>车辆管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 12 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/carschedule_all.do"> <i class="fa fa-calendar"></i>
					<span>排班管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 16 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/pages/stationManage.jsp"> <i
					class="fa fa-map-marker"></i> <span>站点管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 20 }">
			<li class="active treeview"><a href="${pageContext.request.contextPath}/pages/lineManage.jsp"> <i class="fa fa-road"></i>
					<span>线路管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 24 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/findUserFirstPage.do"> <i class="fa fa-user-plus"></i>
					<span>用户管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 28 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/findRoleFirstPage.do"> <i
					class="fa fa-check-square-o"></i> <span>角色管理</span> </a></li>
					</c:when>
					<c:when test ="${UserRoleActionsId == 32 }">
			<li class="treeview"><a href="${pageContext.request.contextPath}/pages/dataSave.jsp"> <i class="fa fa-save"></i>
					<span>数据备份</span> </a></li>
					</c:when>
					</c:choose></c:forEach>
		</ul>
			</section>
			<!-- /.sidebar -->
		</aside>

		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper" style="background-color:#f2f2f2;">
			<!-- Main content -->
			<section class="content" style="padding:0px;margin:0px;">

				<div class="map" id="map">
				<div id="test"></div>

					<!--  <div
					style="right:100px;
	top:150px; width:380px;position:absolute;">
					<div>
						
						<button class="addsl" data-toggle="modal" data-target="#addline">增加线路</button>
						<a style="margin-left:8px;"><img
							src="${pageContext.request.contextPath}/dist/img/export.png">
						</a> <a style="float:right;"><img
							src="${pageContext.request.contextPath}/dist/img/showStation0.png">
						</a>
					</div>
					<form id='stationSearchForm' style="margin-top:20px;"
						action='${pageContext.request.contextPath}/getStationInfo.do'>
						<input type="text" value="输入站点" class="form-control"
							id="navbar-search-input"
							style="background:#ffffff;color:#666; width:290px; margin-left:50px;">
						<a style="color:#ffffff;cursor:pointer;" data-toggle="modal"
							data-target="#myModal"><button class="btn btn-info"
								id="bstationSearch" name="query"
								style="background:#ff9900;border:none;float:right;margin-top:-33px;heigt:37px;">
								<i class="fa   fa-search" style="color:#fffff;"></i>
							</button> </a>
					</form>

				</div> 
				</div>-->
				</div>
				<!-- addline -->
						<div class="modal fade" id="addline" tabindex="-1" role="dialog"
					aria-labelledby="myModalLabel" aria-hidden="true" style="font-family::Microsoft YaHei; ">
					<div class="modal-dialog">
						<div class="modal-content"
							style="width:400px;height:300px;position:relative; top:50px;left:100px;">
							<div class="modal-header"
								style="color:#ffffff;background:#ff9900;">
								<button type="button" class="close" data-dismiss="modal"
									aria-hidden="true">
									<i class="fa  fa-close " style="color:#ffffff"></i>
								</button>
								<h4 class="modal-title" id="myModalLabel">添加线路</h4>
							</div>
							<div class="modal-body" style="margin-top:30px;">
								<form id='locStationForm' class="form-horizontal" role="form"
									action='${pageContext.request.contextPath}/saveStation.do'
									method='post'>
									<div class="form-group" style="margin-left:30px; ">
										<label for="lastname" class="col-sm-3 control-label" >线路号</label>
										<div class="col-sm-8">
											<input type="text" class="form-control" id='routeId'
												name="station_location"
												style="background:none;border:1px solid #bcbcbc;color:#000000;"
												placeholder="请输入姓">
												
										</div>
									</div>
									<!-- <div class="form-group" style="margin-left:30px;">
										<label for="lastname" class="col-sm-3 control-label">经过站点</label>
										<div class="col-sm-8">
											<input type="text" class="form-control" name="station_name"
												id="station_name"
												style="background:none;border:1px solid #bcbcbc;color:#000000;"
												placeholder="请输入姓">
										</div>
									</div> -->
									

									


								</form>
							</div>
							<div class="modal-footer" style="padding:0 34%; margin-top:10px;">
								<button type="button" onclick="saveRoute()" class="btn btn-default" id="blocStation"
									style="color:#ffffff;background:#ff9900;">保&nbsp;存</button>
								<button type="button" class="btn btn-default"
									data-dismiss="modal" style="color:#ffffff;background:#a0a0a0;">取&nbsp;消
								</button>
							</div>
						</div>
						<!-- /.modal-content -->
					</div>
					<!-- /.modal -->
				</div>

	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
					aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content"
							style="width:330px;height:350px;position:relative; top:220px;left:625px;">
							<div class="modal-header" style="background:#ffffff;">
								<button type="button" class="close" data-dismiss="modal"
									aria-hidden="true">
									<i class="fa  fa-close " style="color:#ff9900"></i>
								</button>

							</div>
							<div class="modal-body">
								<table class="table table-bordered">
									<tr style="background:#ff9900;color:#ffffff;text-align:center;">
										<td>线路号</td>
										<td>乘车率</td>
										<td>线路总人数</td>
							
									</tr>
									<tr style=text-align:center;">
										<td id="station_num"></td>
										<td id="real_num"></td>
										<td id="real_num"></td>
									</tr>
								</table>
								<table class="table table-bordered">
									<tr style="background:#ff9900;color:#ffffff;text-align:center;">
										<td colspan="4">经过站点</td>
									</tr>
									<tr style=text-align:center;">
										<td id="employeeName">xx站</td>
										<td id="employeeName">xx站</td>
										<td id="employeeName">xx站</td>
										<td id="employeeName">xx站</td>
										
									</tr>
								</table>
							</div>

						</div>
						<!-- /.modal-content -->
					</div>
					<!-- /.modal -->
				</div>
			</section>
			<!-- /.content -->
		</div>
		
		<!-- /.content-wrapper -->

		<!-- ./wrapper -->

		<!-- jQuery 2.2.0 -->
		<script
			src="${pageContext.request.contextPath}/plugins/jQuery/jQuery-2.2.0.min.js"></script>
		<!-- jQuery UI 1.11.4 -->
		<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
		<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
		<script>
			$.widget.bridge('uibutton', $.ui.button);
		</script>
		<!-- Bootstrap 3.3.6 -->
		<script
			src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>
		<!-- Morris.js charts -->
		<script
			src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
		<script
			src="${pageContext.request.contextPath}/plugins/morris/morris.min.js"></script>
		<!-- Sparkline -->
		<script
			src="${pageContext.request.contextPath}/plugins/sparkline/jquery.sparkline.min.js"></script>
		<!-- jvectormap -->
		<script
			src="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
		<script
			src="${pageContext.request.contextPath}/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
		<!-- jQuery Knob Chart -->
		<script
			src="${pageContext.request.contextPath}/plugins/knob/jquery.knob.js"></script>
		<!-- daterangepicker -->
		<script
			src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
		<script
			src="${pageContext.request.contextPath}/plugins/daterangepicker/daterangepicker.js"></script>
		<!-- datepicker -->
		<script
			src="${pageContext.request.contextPath}/plugins/datepicker/bootstrap-datepicker.js"></script>
		<!-- Bootstrap WYSIHTML5 -->
		<script
			src="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
		<!-- Slimscroll -->
		<script
			src="${pageContext.request.contextPath}/plugins/slimScroll/jquery.slimscroll.min.js"></script>
		<!-- FastClick -->
		<script
			src="${pageContext.request.contextPath}/plugins/fastclick/fastclick.js"></script>
		<!-- AdminLTE App -->
		<script src="${pageContext.request.contextPath}/dist/js/app.min.js"></script>
		<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
		<script
			src="${pageContext.request.contextPath}/dist/js/pages/dashboard.js"></script>
		<!-- AdminLTE for demo purposes -->
		<script src="${pageContext.request.contextPath}/dist/js/demo.js"></script>
		<script src="${pageContext.request.contextPath}/dist/js/jquery.min.js"></script>
		
</body>
</html>

<script type="text/javascript">
var map = new BMap.Map("map", {
		enableMapClick : false
	});
	var point = new BMap.Point(116.400244, 39.92556);
	map.centerAndZoom(point, 12);
	map.enableScrollWheelZoom();
	
	$("#map").append("<div style='right:100px; top:100px; width:380px;position:absolute;'> <div><button class='addsl' data-toggle='modal' data-target='#addline'>增加线路</button><a style='margin-left:8px;'><img src='${pageContext.request.contextPath}/dist/img/export.png'></a> <a style='float:right;'><img src='${pageContext.request.contextPath}/dist/img/showStation0.png'></a></div><form id='stationSearchForm' style='margin-top:20px;' action='${pageContext.request.contextPath}/getStationInfo.do'><input type='text' value='输入线路号' class='form-control'id='navbar-search-input'style='background:#ffffff;color:#666; width:290px; margin-left:50px;'><a style='color:#ffffff;cursor:pointer;' data-toggle='modal' data-target='#myModal'><button class='btn btn-info' id='bstationSearch' name='query' style='background:#ff9900;border:none;float:right;margin-top:-33px;heigt:37px;'><i class='fa   fa-search' style='color:#fffff;'></i></button> </a></form></div>");
		

	
	var marker;
	var startEndPoint;
	var opts = {
		width : 250,
		height : 140,
		enableCloseOnClick : false

	}



	$(document).ready($.ajax({
		type:"POST",
		url:"${pageContext.request.contextPath}/findAllStation.do",
		success:function(message,status){
			if(status == "success"){
				var stations = message;
				setStationMessage(stations);
			}
		}
	
	}));
	
	
	function setStationMessage(stations){		
		for(var i = 0; i < stations.length; i++){
			var strPoint = stations[i].coordinate;
			var point = strPoint.split("|");
			var mapPoint = new BMap.Point(point[0],point[1]);
			var pointMarker = new BMap.Marker(mapPoint);
			map.addOverlay(pointMarker);
			var label = new BMap.Label(stations[i].station_name, {
								offset : new BMap.Size(20, -10)
							});
			
			
			pointMarker.setLabel(label);
			(function(){
				pointMarker.addEventListener("click",function(){
					showStartEnd(this);
				});
			})();
			
			
		}
	}
	
	function showStartEnd(thisMarker){
		var startEndButton = "<input type='button' id='start' value='设置为起点' onclick='start()' /><input type='button' id='end' value='设置为终点' onclick='end()'/><input type='hidden' id='point' value='"+thisMarker.getPosition().lng+"|"+thisMarker.getPosition().lat+"' />";
		var infoWindow = new BMap.InfoWindow(startEndButton);
		thisMarker.openInfoWindow(infoWindow);
	}
	
	var startPoint;
	var points = new Array();
	function wayPoints(points){
		this.points = points;
	}
	var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true ,enableDragging : true}});
	function start(){
		var sPoint1 = document.getElementById('point').value;
		var sPointArray1 = sPoint1.split("|");
		startPoint = new BMap.Point(sPointArray1[0],sPointArray1[1]);
	}
	
	var wayPoints;
	var myDragPois;
	var endPoint;
	function end(){
	
		var sPoint = document.getElementById('point').value;
		var sPointArray = sPoint.split("|");
		endPoint = new BMap.Point(sPointArray[0],sPointArray[1]);
		
		wayPoints = new Object();
		wayPoints.points = points;
		//for(var i = 0 ; i < wayPoints.points.length; i++){
			//alert(wayPoints.points[i].lng + ".."+wayPoints.points[i].lat);
		//}
		var testpoints = new Array();
		
		driving.search(startPoint,endPoint);
		driving.setSearchCompleteCallback(function(){
			myDragPois = driving.getResults().getPlan(0).getDragPois();
		});

	}
	
	function saveRoute(){
		var route="";
		for(var i = 0 ; i < myDragPois.length;i++){
			var myPoint = myDragPois[i].point;
			var sPoint = myPoint.lng+"|"+myPoint.lat;
			route = route+sPoint+",";
		}
		var sStartPoint = startPoint.lng+"|"+startPoint.lat;
		var sEndPoint = endPoint.lng+"|"+endPoint.lat;
		route = sStartPoint+","+route+sEndPoint;
		var routeId = $("#routeId").val();
		$.ajax({
			type : "post",
			data : "line_id="+routeId+"&pass_station="+route,
			url: "${pageContext.request.contextPath}/saveRoute.do",
			success:function(msg){
				alert("保存线路成功");
			}
		});
	}

	function showRoute(){
		$.ajax({
			type : "post",
			url: "${pageContext.request.contextPath}/getAllRoute.do",
			success:function(msg,status){
				if(status == "success"){
					var lines = msg;
					test(lines);
				}
			}
		});
	}
	
	function test(lines){
		var stations = new Array();
		for(var i = 0; i < lines.length; i++){
			var sRouteStation = lines[i].pass_station;
			var stations = sRouteStation.split(",");
			
			test2(stations);
		}
	}
	function test2(stations){
	
		var start = stations[0].split("|");
		
		var p1 = new BMap.Point(start[0],start[1]);
		var length = stations.length-1;
		var end = stations[length].split("|");
		var p2 = new BMap.Point(end[0],end[1]);
		var waypoints = new Object();
		var passStations = new Array();
		for(var i = 0; i < stations.length; i++){
			var station = stations[i].split("|");
			var point = new BMap.Point(station[0],station[1]);
			passStations.push(point);
		}
		
		waypoints.points = passStations;
		
		showTheRoute(p1,p2,waypoints);
	}
	
	function showTheRoute(p1,p2,waypoints){
	
		driving.search(p1,p2,waypoints);
	}
	
		
</script>
